import { useEffect, useState } from "react"
import { readBinary } from "@linksaas-git/widget";

function App() {
  const [imgSrc, setImgSrc] = useState("");

  useEffect(() => {
    readBinary().then(data => {
      const chunk = 8 * 1024;
      const dataStrList = [] as string[];
      for (let i = 0; i < data.length / chunk; i++) {
        const buf = data.slice(i * chunk, (i + 1) * chunk);
        dataStrList.push(String.fromCharCode(...buf));
      }
      const dataB64 = btoa(dataStrList.join(""));
      setImgSrc(`data:image/*;base64,${dataB64}`);
    })
  }, []);
  return (
    <>
      {imgSrc != "" && (
        <img src={imgSrc} width="100%"/>
      )}
    </>
  )
}

export default App
